import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 解决导航栏或者底部导航tabBar中的vue-router在3.0版本以上频繁点击菜单报错的问题。
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'Manager',
    component: () => import('../views/Manager.vue'),
    redirect: '/front/homeFront',  // 重定向到前台主页
    children: [
      { path: '403', name: 'NoAuth', meta: { name: '无权限' }, component: () => import('../views/manager/403') },
      { path: 'home', name: 'Home', meta: { name: '系统首页' }, component: () => import('../views/manager/Home') },
      { path: 'admin', name: 'Admin', meta: { name: '管理员信息' }, component: () => import('../views/manager/Admin') },
      { path: 'adminPerson', name: 'AdminPerson', meta: { name: '个人信息' }, component: () => import('../views/manager/AdminPerson') },
      { path: 'password', name: 'Password', meta: { name: '修改密码' }, component: () => import('../views/manager/Password') },
      { path: 'notice', name: 'Notice', meta: { name: '公告信息' }, component: () => import('../views/manager/Notice') },
    ]
  },
  {
    path: '/front',
    name: 'Front',
    component: () => import('../views/Front.vue'),
    children: [
      { path: 'homeFront', name: 'HomeFront', meta: { name: '首页' }, component: () => import('../views/front/HomeFront') },
      { path: 'homeClick', name: 'HomeClick', meta: { name: '系统首页' }, component: () => import('../views/front/HomeClick') },
      { path: 'homeDetail', name: 'HomeDetail', meta: { name: '系统首页' }, component: () => import('../views/front/HomeDetail') },
      { path: 'drive', name: 'Drive', meta: { name: '驱动' }, component: () => import('../views/front/Drive.vue') },
      { path: 'driveClick', name: 'DriveClick', meta: { name: '驱动' }, component: () => import('../views/front/DriveClick.vue') },
      { path: 'driveDetail', name: 'DriveDetail', meta: { name: '驱动' }, component: () => import('../views/front/DriveDetail.vue') },
      { path: 'success', name: 'Success', meta: { name: '反馈成功' }, component: () => import('../views/front/Success') },
      { path: 'feedBack', name: 'FeedBack', meta: { name: '用户反馈' }, component: () => import('../views/front/FeedBack') },
      { path: 'contact', name: 'Contact', meta: { name: '关于我们' }, component: () => import('../views/front/Contact') },
      { path: 'search', name: 'Search', meta: { name: '搜索结果' }, component: () => import('../views/front/Search') },
      { path: 'forum', name: 'Forum', meta: { name: '论坛' }, component: () => import('../views/front/Forum') },
      { path: 'download', name: 'Download', meta: { name: '论坛' }, component: () => import('../views/front/Download') },
      { path: 'empty', name: 'Empty', meta: { name: '空' }, component: () => import('../views/front/Empty') },
      { path: 'person', name: 'Person', meta: { name: '个人信息' }, component: () => import('../views/front/Person') },
      { path: 'typeface', name: 'Typeface', meta: { name: '字体' }, component: () => import('../views/front/Typeface.vue') },
      { path: 'faceClick', name: 'FaceClick', meta: { name: '字体' }, component: () => import('../views/front/FaceClick.vue') },
      { path: 'faceDetail', name: 'FaceDetail', meta: { name: '字体' }, component: () => import('../views/front/FaceDetail.vue') },
    ]
  },
  { path: '/login', name: 'Login', meta: { name: '登录' }, component: () => import('../views/Login.vue') },
  { path: '/register', name: 'Register', meta: { name: '注册' }, component: () => import('../views/Register.vue') },
  { path: '*', name: 'NotFound', meta: { name: '无法访问' }, component: () => import('../views/404.vue') },
  { path: '/searchNew', name: 'SearchNew', meta: { name: '直接搜索' }, component: () => import('../views/SearchNew.vue') },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.afterEach((to, from) => {
  // 跳转到页面顶部
  window.scrollTo(0, 0);
});

export default router
